import { routerRedux } from 'dva/router';
import { checkTimeBegin } from '../services/api';

export default {
  namespace: 'time',

  state: {
    status: undefined,
  },

  effects: {
    *grapTime({ payload }, { call, put }) {
      yield call(checkTimeBegin, payload);
      yield put({
        type: 'changTimeStatus',
        payload: true,
      });
      yield put(routerRedux.push('/box/Time'));
    },
  },

  reducers: {
    changeTimeStatus(state, { payload }) {
      return {
        ...state,
        status: payload.status,
        type: payload.type,
      };
    },
  },

};
